﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TCCVoigt.Models;

namespace TCCVoigt.Controllers
{
    public class FuncaoController : Controller
    {
        private TCCVoigtEntities db = new TCCVoigtEntities();

        //
        // GET: /Funcao/

        public ActionResult Index()
        {
            return View(db.Funcao.ToList());
        }

        //
        // GET: /Funcao/Details/5

        public ActionResult Details(int id = 0)
        {
            Funcao funcao = db.Funcao.Single(f => f.Codigo == id);
            if (funcao == null)
            {
                return HttpNotFound();
            }
            return View(funcao);
        }

        //
        // GET: /Funcao/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Funcao/Create

        [HttpPost]
        public ActionResult Create(Funcao funcao)
        {
            if (ModelState.IsValid)
            {
                db.Funcao.AddObject(funcao);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(funcao);
        }

        //
        // GET: /Funcao/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Funcao funcao = db.Funcao.Single(f => f.Codigo == id);
            if (funcao == null)
            {
                return HttpNotFound();
            }
            return View(funcao);
        }

        //
        // POST: /Funcao/Edit/5

        [HttpPost]
        public ActionResult Edit(Funcao funcao)
        {
            if (ModelState.IsValid)
            {
                db.Funcao.Attach(funcao);
                db.ObjectStateManager.ChangeObjectState(funcao, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(funcao);
        }

        //
        // GET: /Funcao/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Funcao funcao = db.Funcao.Single(f => f.Codigo == id);
            if (funcao == null)
            {
                return HttpNotFound();
            }
            return View(funcao);
        }

        //
        // POST: /Funcao/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Funcao funcao = db.Funcao.Single(f => f.Codigo == id);
            db.Funcao.DeleteObject(funcao);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}